// ignore_for_file: prefer_const_constructors

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutterdemo/components/shop_cart.dart';
import '../../common/calc.dart';

class ClassifiPage extends StatefulWidget {
  // ignore: prefer_const_constructors_in_immutables
  ClassifiPage({Key? key}) : super(key: key);

  @override
  _ClassifiPageState createState() => _ClassifiPageState();
}

class _ClassifiPageState extends State<ClassifiPage>
    with AutomaticKeepAliveClientMixin {
  int titleIndex = 0;

  // 侧边栏
  Widget sliderW() {
    List titleList = [
      "京东超市",
      "国际名牌",
      "奢侈品",
      "京东超市",
      "国际名牌",
      "奢侈品",
      "京东超市",
      "国际名牌",
      "奢侈品",
      "京东超市",
      "国际名牌",
      "奢侈品",
      "京东超市",
      "国际名牌",
      "奢侈品"
    ];
    return ListView.builder(
        itemCount: titleList.length,
        physics: BouncingScrollPhysics(),
        itemBuilder: (BuildContext context, int index) {
          return Ink(
            color: titleIndex == index
                ? Theme.of(context).primaryColor
                : Colors.white,
            child: InkWell(
              onTap: () {
                setState(() {
                  titleIndex = index;
                });
              },
              child: Container(
                  height: Calc.width(100),
                  decoration: BoxDecoration(
                      border: Border(
                          bottom: BorderSide(
                              color: index != titleList.length - 1
                                  ? Color.fromRGBO(233, 233, 233, 1)
                                  : Colors.white,
                              width: 1))),
                  child: Center(
                    child: Text(
                      titleList[index],
                      style: TextStyle(
                          fontSize: 14,
                          color: titleIndex == index
                              ? Colors.white
                              : Colors.black),
                    ),
                  )),
            ),
          );
        });
  }

  // 内容
  Widget _contentW() {
    return Wrap(
      children: [
        _contentItem(),
      ],
    );
  }

  Widget _contentItem() {
    return Container(
      height: Calc.width(300),
      width: double.infinity * 0.05,
      child: Image.network(
        "https://img2.baidu.com/it/u=3443839355,3082841722&fm=15&fmt=auto",
        fit: BoxFit.cover,
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    Calc.init(context);
    return Scaffold(
      backgroundColor: Color.fromRGBO(233, 233, 233, 1),
      body: Row(
        children: [
          Expanded(
            flex: 2,
            child: Container(
              height: double.infinity,
              child: sliderW(),
            ),
          ),
          Expanded(
            flex: 5,
            child: Container(
              // decoration: BoxDecoration(color: Color.fromRGBO(233, 233, 233, 1)),
              height: double.infinity,
              child: ListView(
                physics: BouncingScrollPhysics(),
                padding: EdgeInsets.all(Calc.width(20)),
                children: [ShopCart()],
              ),
            ),
          ),
        ],
      ),
    );
  }

  @override
  // TODO: implement wantKeepAlive
  bool get wantKeepAlive => true;
}
